package com.workcell.workdata.im.component.redis;

import com.workcell.workdata.im.component.redis.base.LongRedisTemplate;
import com.workcell.workdata.im.entity.GroupMember;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class GroupMemberRedisTemplate extends LongRedisTemplate {

	private static final String CACHE_PREFIX = "GROUP_MEMBER_";

	@Autowired
	public GroupMemberRedisTemplate(RedisConnectionFactory connectionFactory) {
		super(connectionFactory);
	}

	public void add(GroupMember member) {
		String key = CACHE_PREFIX + member.getGroupId();
		super.add(key,member.getUid());
	}

	public void add(Long groupId , long uid) {
		String key = CACHE_PREFIX + groupId;
		super.add(key,uid);
	}

	public void add(Long groupId , List<Long> idList) {
		String key = CACHE_PREFIX + groupId;
		super.add(key,idList);
	}


	public List<Long> list(long groupId) {
		String key = CACHE_PREFIX + groupId;
		return super.findList(key);
	}

	public void remove(long groupId) {
		String key = CACHE_PREFIX + groupId;
		super.delete(key);
	}

	public void remove(Long groupId , List<Long> idList) {
		String key = CACHE_PREFIX + groupId;
		super.boundSetOps(key).remove(idList.toArray());
	}

	public void remove(GroupMember member) {
		String key = CACHE_PREFIX + member.getGroupId();
		super.remove(key,member.getUid());
	}
}
